package main

import (
	"flag"
	"znet/leaf"
	"znet/glog"
	"demo/gate/conf"
	"demo/gate/rpcservice"
	"demo/gate/gate"
	"demo/gate/service"
	"demo/gate/agents"
)

const confPath  = "conf/gate/server.json"

const Version  = "1.0.0"

func main() {
	flag.Parse()
	// 配置
	initConfig()
	// 日志 在初始化之前不要调用glog
	initLog()
	defer glog.Flush()

	// 启动
	leaf.Run(
		service.Module,
		rpcservice.Module,
		gate.Module,
		agents.Module,
	)
}
// 配置
func initConfig()  {
	configPath:= flag.String("conf", confPath, "config path")
	flag.Parse()
	conf.Server.Configure(*configPath)
}
// 日志
func initLog()  {
	glog.LogDir  = conf.Server.LogDir
	if conf.Server.LogMaxSize > 0{
		glog.MaxSize = conf.Server.LogMaxSize
	}
	if conf.Server.FlushInterval > 0 {
		glog.FlushInterval = conf.Server.FlushInterval
	}
	glog.OnInit(conf.Server.ToStderr)
}